import { Component } from '@angular/core';
import { Journey } from './journey';

import { OnInit } from '@angular/core';
import { Router } from '@angular/router';

import { JourneyService } from './journey.service';

@Component({
  selector: 'my-journeys',
  templateUrl: './journey.component.html'
})

export class JourneyComponent implements OnInit {
  ngOnInit() {
    this.getJourneys();
  }

  journeys: Journey[];
  selectedJourney: Journey;

  start_time = new Date().toDateString();
  end_time = new Date().toDateString();

  datePickerConfig = {
    "firstDayOfWeek": "su",
    "calendarsAmount": 1,
    "format": "YYYY-MM-DD",
    "monthFormat": "YYYY-MM-DD",
    "closeOnSelect": true,
    "closeOnSelectDelay": 100,
    "weekdayNames": {
      "su": "日",
      "mo": "一",
      "tu": "二",
      "we": "三",
      "th": "四",
      "fr": "五",
      "sa": "六"
    },
    "disableKeypress": true
  };

  onSelect(journey: Journey) { this.selectedJourney = journey; }

  constructor(
    private router: Router,
    private journeyService: JourneyService) {
  }

  getJourneys() {
    this.journeyService.searchJourneys(this.start_time, this.end_time).then(journeys => this.journeys = journeys);
  }

  search() {
    this.getJourneys();
  }
}
